package com.neuedu.controller;

import com.neuedu.core.NeueduException;
import com.neuedu.entity.Resume;
import com.neuedu.entity.ResumeSubmit;
import com.neuedu.service.ResumeService;
import com.neuedu.vo.ResultJson;
import io.minio.errors.*;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.apache.xmlbeans.XmlException;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * 简历Controller：处理前端简历相关请求
 */
@RestController // 标记为REST接口控制器（= @Controller + @ResponseBody）
@RequestMapping("/resume") // 接口统一前缀，避免URL冲突
public class ResumeController {

    // 依赖注入Service实例（Spring自动注入ServiceImpl对象）
    @Resource
    private ResumeService resumeService;
    @PostMapping("/saveOrUpdate") // 接口路径：/api/resume/saveOrUpdate
    public ResultJson<Resume> saveOrUpdateResume(Resume dto, MultipartFile file, Long login_id) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        dto.setUserId(login_id);
        Resume savedResume = resumeService.saveOrUpdateResume(dto, file);
        return ResultJson.success(savedResume, "简历保存成功");
    }

    @GetMapping("/getByUserId") // 接口路径：/api/resume/getByUserId
    public ResultJson<Resume> getResumeByUserId(Long login_id) {
        Resume resume = resumeService.getResumeByUserId(login_id);
        if (resume == null) {
            return ResultJson.success(null, "该用户暂无简历");
        }
        return ResultJson.success(resume, "简历查询成功");
    }

    @GetMapping("/six") // 接口路径：/api/resume/getByUserId
    public ResultJson<String> Six(Long login_id) {
        return ResultJson.success(null, "简历查询成功");
    }

    @GetMapping("/download")
    public void downloadResume(Long login_id, HttpServletResponse response) throws XmlException, IOException {
        resumeService.downloadResume(login_id, response);
    }
}
